import {
  scrollMixin
} from 'utils/mixin';
import cTitle from "components/title";
export default {
  mixins: [scrollMixin], // 加载更多
  data() {
    return {
      screenTime: [2022.04, 2022.05, 2022.06], //筛选时间
      titleTop: ['会员昵称', '本月', '本月', '本年度'], //标题
      titleButton: ['ID','订单数', '订单总额', '订单总额'], //标题
      slideDown: false, //下拉筛选是否显示
      selectedTime: '', //已选中时间
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(),
      newTime: this.dealdate(new Date()),
      teamSalesList: []
    };
  },
  activated() {
    this.getData(this.newTime)
  },
  mounted(){

  },
  methods: {
    //获取数据
    getData(month) {
      console.log(month)
      month = parseInt(month.replace('-', ''))

      $http.post('plugin.agent-earnings.frontend.sales-statistical.get-sales-detail', {
        month_str: month
      }).then((res) => {
          if (res.result === 1) {
            let data = res.data
            this.teamSalesList = data.list.data
          } else {
            this.$dialog.alert({
              message: res.msg
            });
          }
        },
        function(response) {
          // error callback
        });
    },
    changeSlideDown(value) { //弹出时间选择弹窗
      if (value) {
        this.selectedTime= this.dealdate(value)
        this.getData(this.selectedTime)
      }
      this.slideDown = !this.slideDown

    },
    cancelTimePopover(){ //时间取消修改
      this.slideDown = false
    },
    screen(value) { //筛选
      this.selectedTime = value
    },
    formatter(type, val) {
      if (type === 'month') {
        return `${val}月`;
      } else if (type === 'day') {
        return `${val}日`;
      }
      return val;
    },
    dealdate(dealdate) { //时间转换
      const date = new Date(dealdate)
      const year = date.getFullYear()
      let month = date.getMonth() + 1
      month = month < 10 ? "0" + month : month
      let day = date.getDate()
      day = day < 10 ? "0" + day : day
      let hour = date.getHours()
      hour = hour < 10 ? "0" + hour : hour
      let minute = date.getMinutes()
      minute = minute < 10 ? "0" + minute : minute
      let second = date.getSeconds()
      second = second < 10 ? "0" + second : second
      return year + '-' + month;
    },
  },
  components: {
    cTitle
  }
};
